/**
 * 
 */
package com.feib.stms.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.feib.stms.dao.TempUploadFileDao;
import com.feib.stms.model.TempUploadFile;
import com.feib.stms.pagination.PaginatedList;
import com.feib.stms.service.TempUploadFileService;
import com.feib.stms.util.UserUtil;

/**
 * @author Jimmy Liu
 *
 */
@Service("tempUploadFileService")
public class TempUploadFileServiceImpl extends BaseServiceImpl implements TempUploadFileService 
{
	private static final long serialVersionUID = -8556548498846742177L;
	
	@Resource(name="tempUploadFileDao")
	private TempUploadFileDao tempUploadFileDao;

	/* (non-Javadoc)
	 * @see com.feib.stms.service.TempUploadFileService#addTempUploadFile(com.feib.stms.model.TempUploadFile)
	 */
	public int addTempUploadFile(TempUploadFile tempUploadFile) {
		
		Date now = new Date();
		String updateBy = UserUtil.getUserGroup().getGroupNo()+"_"+UserUtil.getUserId();
		tempUploadFile.setUploadDate(now);
		tempUploadFile.setCreatedDate(now);
		tempUploadFile.setCreatedBy(updateBy);
		tempUploadFile.setUpdatedDate(now);
		tempUploadFile.setUpdatedBy(updateBy);
		return tempUploadFileDao.insert(tempUploadFile);
	}

	public List<TempUploadFile> findValidateFileByFileName(String fileName, Long excludePk) {
		return tempUploadFileDao.queryValidateFileByFileName(fileName, excludePk);
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.TempUploadFileService#findPaginatedListByTempUploadFile(com.feib.stms.model.TempUploadFile, java.util.Date, java.util.Date, java.util.List, com.feib.stms.pagination.PaginatedList)
	 */
	public PaginatedList<TempUploadFile> findPaginatedListByTempUploadFile(TempUploadFile tempUploadFile, Date uploaddDateFrom, Date uploadDateTo, List<String> fileFormats, PaginatedList<TempUploadFile> paginatedList) {
		return tempUploadFileDao.queryForPaginatedListByTempUploadFile(tempUploadFile, uploaddDateFrom, uploadDateTo, fileFormats, paginatedList);
	}
	
	public PaginatedList<TempUploadFile> findPaginatedListByFormatIs2(TempUploadFile tempUploadFile, Date uploaddDateFrom, Date uploadDateTo, PaginatedList<TempUploadFile> paginatedList) {
		return tempUploadFileDao.queryForPaginatedListByFormatIs2(tempUploadFile, uploaddDateFrom, uploadDateTo, paginatedList);
	}
	
	
	public TempUploadFile findTempUploadFileByPk(Long tempUploadFilePk)
	{
		return tempUploadFileDao.getTempUploadFileByPk(tempUploadFilePk);
	}
	
	public int deleteByPk(Long tempUploadFilePk)
	{
		return tempUploadFileDao.deleteByPk(tempUploadFilePk);
	}

	public int updateImportStatus(TempUploadFile tempUploadFile) 
	{
		Date now = new Date();
		tempUploadFile.setCreatedDate(now);
		tempUploadFile.setCreatedBy(UserUtil.getUserGroup().getGroupNo()+"_"+UserUtil.getUserId());
		return tempUploadFileDao.updateFileImportStatus(tempUploadFile);
	}

}
